﻿
using System.Collections.Generic;
using System.Data;
using System;
namespace ZHDJ.MobileInterface
{
    public partial class GetCircleDynamicInfoList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            CircleDynamicInfoOutParam result = new CircleDynamicInfoOutParam();
            CircleDynamicInfoInParam param = new CircleDynamicInfoInParam();
            string logMsg = "";
            bool isFlag = true;
                 
            try
            {
                param = inParam as CircleDynamicInfoInParam;
                if (string.IsNullOrEmpty(param.community_id))
                {
                    result.code = "0";
                    result.desc = "群ID不能为空";

                    isFlag = false;
                }

                if (isFlag)
                {
                    if (param.page_no * param.page_count <= 0)
                    {
                        result.code = "0";
                        result.desc = "当前页,以及页记录条数必须为大于0的正整数";

                        isFlag = false;
                    }
                }

                if (isFlag)
                {
                    if (string.IsNullOrEmpty(param.type) || (param.type != "1" && param.type != "2"))
                    {
                        result.code = "0";
                        result.desc = "信息类别必须为1(留言),或者2(活动)";

                        isFlag = false;
                    }
                }

                if(isFlag)
                {
                    DataSet ds = InterfaceHelper.GetCircleDynamicInfoList(param.type, param.community_id, param.page_no, param.page_count);
                    if (ds != null && ds.Tables.Count == 2)
                    { 
                        CircleDynamicInfo itemTemp;
                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[0].Rows[0][0]), param.page_count);
                        foreach (DataRow dr in ds.Tables[1].Rows)
                        {
                            itemTemp = new CircleDynamicInfo();
                            itemTemp.activity_addr = dr["activity_addr"].ToString();
                            itemTemp.activity_content = dr["activity_content"].ToString();
                            itemTemp.activity_id = dr["activity_id"].ToString();
                            itemTemp.activity_time = dr["activity_time"].ToString() + " - " + dr["ActivityEndTime"].ToString();
                            itemTemp.enter_nums = dr["enter_nums"].ToString();
                            itemTemp.msg_content = dr["msg_content"].ToString();
                            itemTemp.publish_time = dr["publish_time"].ToString();
                            itemTemp.user_head = CommonUtils.AppAddress + SXT.Utility.FileServer.QueryFileUrl(dr["user_head"].ToString());
                            itemTemp.user_id = dr["user_id"].ToString();
                            itemTemp.user_name = dr["user_name"].ToString();
                            itemTemp.Is_party_member = dr["Is_party_member"].ToString();
                            itemTemp.activity_name = dr["activity_name"].ToString();

                            result.data.list.Add(itemTemp);
                        }
                    }  
                }
                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员"; 
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode +"-GetCircleDynamicInfoList", SerializeHelper.JsonSerializer<CircleDynamicInfoInParam>(param), logMsg); 
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<CircleDynamicInfoInParam, CircleDynamicInfoOutParam>();
            else
                SafeProcessRequest<CircleDynamicInfoInParam, CircleDynamicInfoOutParam>();
        }
    }

    #region 请求参数
    public class CircleDynamicInfoInParam
    {
        /// <summary>
        /// 用户ＩＤ(暂时不用)
        /// </summary>
        public string user_id
        { get; set; }

        /// <summary>
        /// 必填，	圈子ID
        /// </summary>
        public string community_id
        { get; set; }

        /// <summary>
        /// 必填， 信息类别 1：留言，2：活动
        /// </summary>
        public string type
        { get; set; } 

        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }
    }
    #endregion

    #region 结果参数
    public class CircleDynamicInfoOutParam
    {
        public CircleDynamicInfoOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new CircleDynamicInfoList();
        }

        /// <summary>
        /// 返回结果 具体见接口返回对照码 1	成功 0	失败 2	请求非法 加密结果和传入的MD5字符串进行比较，如果相同则执行接口操作，否则返回1001错误响应码
        /// </summary>
        public string code
        { get; set; }

        /// <summary>
        /// 结果描述 成功和失败都需要
        /// </summary>
        public string desc
        { get; set; }

        /// <summary>
        /// 圈子的动态信息列表
        /// </summary>
        public CircleDynamicInfoList data
        { get; set; }
    }

    public class CircleDynamicInfoList
    {
        public CircleDynamicInfoList()
        {
            total_pages = 0;
            list = new List<CircleDynamicInfo>();
        }

        public List<CircleDynamicInfo> list { get; set; }

        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }
     
    /// <summary>
    /// 圈子的动态信息
    /// </summary>
    public class CircleDynamicInfo
    {  
        /// <summary>
        ///	成员ID		
        /// </summary>
        public string user_id
        { get; set; }

        /// <summary>
        ///	成员名称		
        /// </summary>
        public string user_name
        { get; set; }

        /// <summary>
        ///	成员头像		
        /// </summary>
        public string user_head
        { get; set; }

        /// <summary>
        ///	发布时间		
        /// </summary>
        public string publish_time
        { get; set; } 

        /// <summary>
        ///	是否是党员
        /// </summary>
        public string Is_party_member
        { get; set; }

        /// <summary>
        ///	留言内容		
        /// </summary>
        public string msg_content
        { get; set; }

        /// <summary>
        ///	活动ID	
        /// </summary>
        public string activity_id
        { get; set; }

        /// <summary>
        ///	活动名称	
        /// </summary>
        public string activity_name
        { get; set; }

        /// <summary>
        ///	活动地点		
        /// </summary>
        public string activity_addr
        { get; set; }

        /// <summary>
        ///	活动时间		
        /// </summary>
        public string activity_time
        { get; set; }

        /// <summary>
        ///	活动内容		
        /// </summary>
        public string activity_content
        { get; set; }

        /// <summary>
        ///	已报名人数		
        /// </summary>
        public string enter_nums
        { get; set; } 
    }
    #endregion 
}